Skip to content

fix(editor): deduplicate blank tab indexes to fix incorrect new docum…#473

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pppanghu77:master
Jun 9, 2026
Merged

fix(editor): deduplicate blank tab indexes to fix incorrect new docum…#473
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pppanghu77:master

Conversation

@pppanghu77

Copy link
Copy Markdown
Contributor

…ent naming

  • Add std::unique + erase after sorting in getBlankFileIndex() to remove duplicate index numbers
  • Prevent newly created documents from being stuck with the same "Untitled N" name when tabs with duplicate titles are dragged between windows

修复(editor): 对空白标签索引去重以修复新文档命名错误

  • 在 getBlankFileIndex() 的排序后增加 std::unique + erase 去除重复的索引编号
  • 修复跨窗口拖入同名"未命名文档"标签后,新建文档名称始终为同一编号的问题

Log: 修复跨窗口拖拽标签导致新文档命名计数器异常的 bug
Bug: https://pms.uniontech.com/bug-view-251843.html

…ent naming

- Add std::unique + erase after sorting in getBlankFileIndex() to remove duplicate index numbers
- Prevent newly created documents from being stuck with the same "Untitled N" name when tabs with duplicate titles are dragged between windows

修复(editor): 对空白标签索引去重以修复新文档命名错误

- 在 getBlankFileIndex() 的排序后增加 std::unique + erase 去除重复的索引编号
- 修复跨窗口拖入同名"未命名文档"标签后,新建文档名称始终为同一编号的问题

Log: 修复跨窗口拖拽标签导致新文档命名计数器异常的 bug
Bug: https://pms.uniontech.com/bug-view-251843.html

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @pppanghu77, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

这段代码的修改是针对getBlankFileIndex()函数的,主要添加了一个去重操作,以处理在不同窗口之间拖动具有相同"Untitled N"名称的标签页时可能出现的索引计算错误问题。让我对这段代码进行详细分析:

语法逻辑

  • 语法正确,使用了std::sortstd::unique标准库函数对tabIndexes向量进行排序和去重。
  • 注释清晰,解释了为什么需要去重操作。

代码质量

  • 代码质量良好,添加的注释提高了代码的可读性和可维护性。
  • 使用STL算法实现去重,符合现代C++编程风格。

代码性能

  • std::sort的时间复杂度为O(n log n),std::unique的时间复杂度为O(n),其中n是tabIndexes的大小。
  • 这种实现方式在大多数情况下性能是可以接受的,因为标签页的数量通常不会太多。

代码安全

  • 去重操作可以防止因重复索引导致的潜在错误,提高了代码的健壮性。
  • 没有发现明显的安全问题。

改进建议

  1. 考虑使用std::unordered_set代替排序+去重的组合,在某些情况下可能更高效:

    std::unordered_set<int> uniqueTabIndexes(tabIndexes.begin(), tabIndexes.end());
    tabIndexes.assign(uniqueTabIndexes.begin(), uniqueTabIndexes.end());
    std::sort(tabIndexes.begin(), tabIndexes.end());

    这样可以在O(n)时间内完成去重,但需要额外的空间。

  2. 如果tabIndexes向量的大小可能会很大,可以考虑在排序前先进行去重操作,这样可以减少排序的数据量:

    tabIndexes.erase(std::unique(tabIndexes.begin(), tabIndexes.end()), tabIndexes.end());
    std::sort(tabIndexes.begin(), tabIndexes.end());
  3. 可以考虑添加断言来确保tabIndexes中的索引是有效的:

    assert(std::all_of(tabIndexes.begin(), tabIndexes.end(), [](int index) { return index >= 0; }));

总体而言,这段代码的修改是合理且必要的,解决了标签页拖动时可能出现的索引计算问题。代码质量良好,没有明显的安全问题。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pppanghu77

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pppanghu77

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 7da46b7 into linuxdeepin:master Jun 9, 2026
17 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants